package com.geek.novel.activity.auth.view.listener

import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import android.view.View
import android.view.View.OnClickListener
import android.widget.EditText
import com.geek.novel.R

/**
 * 显示密码按钮的按钮监听事件
 * Created by admin on 2018/3/26.
 */
class PwdViewerClickListener: OnClickListener {

    private var password_visilbe: Boolean = false

    private lateinit var et_target: EditText

    constructor(et: EditText) {
        this.et_target = et
    }

    override fun onClick(v: View?) {
        et_target.requestFocus()

        if (password_visilbe) {
            v!!.setBackgroundResource(R.drawable.icon_password_invisible)
            et_target.transformationMethod = PasswordTransformationMethod.getInstance()

        } else {
            v!!.setBackgroundResource(R.drawable.icon_password_visible)
            et_target.transformationMethod = HideReturnsTransformationMethod.getInstance()
        }
        password_visilbe = !password_visilbe

        et_target.setSelection(et_target.text.length)

    }

}